import cv2
import numpy as np

# 读取图像
image = cv2.imread('example.jpg')

# 定义源点和目标点
src_points = np.float32([[50,50], [200,50], [50,200], [200,200]])
dst_points = np.float32([[0,0], [250,0], [0,250], [250,250]])

# 获取透视变换矩阵
M = cv2.getPerspectiveTransform(src_points, dst_points)

# 进行透视变换
perspective_image = cv2.warpPerspective(image, M, (300, 300))

# 保存透视变换后的图像
cv2.imwrite('perspective_image.jpg', perspective_image)